home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11886 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: For Experts: How to load a DLL dynamically ?
  5. Date: Sat, 16 Mar 1996 21:29:11 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4ifbpr$67s@news.halcyon.com>
  8. References: <4ibr0a$8f9@nms.telepost.no>
  9. NNTP-Posting-Host: blv-pm3-ip13.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Carsten Arnholm <ca@sesam.dnv.no> wrote:
  13.  
  14. >Hi everyone,
  15.  
  16. >I have a problem which I'm sure some of you experts can solve (???):
  17. >I'm using MSVC++ 4.0 under Windows NT 3.51.
  18.  
  19. >I am unable to load a DLL exporting classes. If the DLL only exports
  20. >simple API functions, I can do:
  21.  
  22. >    // load the library
  23. >    HINSTANCE        myDLL   = LoadLibrary("myDLL.dll");       
  24. >    const FARPROC  myDLLfunc = GetProcAddress(myDLL ,"myDLLfunc");
  25. >    
  26. >    // call a function in the DLL that returns an int
  27. >    int value = myDLLfunc();
  28. >   
  29. >    // DLL no longer needed
  30. >    FreeLibrary(myDLL);
  31.  
  32. >This is straightforward ...
  33.  
  34.  
  35. >But what do I do if I have a DLL which export classes ? i.e.
  36.  
  37. >#ifdef DLL_IMPLEMENTATION
  38. >   #define IMPORT_EXPORT _declspec(dllexport)
  39. >#else
  40. >   #define IMPORT_EXPORT _declspec(dllimport)
  41. >#endif
  42.  
  43. >class IMPORT_EXPORT DLLfoo {   // class exported from dll
  44. >public:
  45. >   DLLfoo();                   // constructor
  46. >   int bar();                  // some member function
  47. >private:
  48. >   int value;
  49. >};
  50.  
  51. >In an application using the DLL, I want to:
  52.  
  53. >   DLLfoo foo;                 // create object from DLL class DLLfoo
  54. >   int somevalue = foo.bar();  // call member function of that class
  55.  
  56. >This is no problem if I link the application using the import library
  57. >of my DLL, but that means that the DLL is "started" together with the 
  58. >application, whether I need it or not.
  59.  
  60. >If I don't link with the import library, there are lots of unresolved
  61. >symbols (of course), and I can't figure out how to do something
  62. >similar to  LoadLibrary/GetProcAddress for my classes and their members.
  63.  
  64. >Any good Ideas ????
  65.  
  66. >Would appreciate if you copied your reply to 
  67. >my e-mail address: ca@sesam.dnv.no
  68.  
  69.  
  70. >Thanks,
  71. >Carsten Arnholm
  72.  
  73. Um, I've never tried to GetProcAddress of a ctor in a late-bound DLL.
  74. Either early-bind the DLL (with an import-library) or GetProcAddress a
  75. 'C' function that instantiates the object for you and returns its
  76. pointer.
  77.  
  78.                     --Norm 
  79.  
  80.  
  81.  
  82.  
  83.  
  84.